Public Class Reports
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents PageSelect1 As SR.WebControls.PageSelect
    Protected WithEvents lblTotal As System.Web.UI.WebControls.Label
    Protected WithEvents lblTotalText As System.Web.UI.WebControls.Label
    Protected WithEvents Pageselect2 As SR.WebControls.PageSelect
    Protected WithEvents dgReports As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Protected WithEvents Header1 As Header
    Private PAGE_SIZE As Integer = 20


    Protected Property PageBO() As DataTable
        Get
            Return CType(Session("MIMS_WRS.Web.Reports"), DataTable)
        End Get
        Set(ByVal Value As DataTable)
            Session("MIMS_WRS.Web.Reports") = Value
        End Set
    End Property

    Private Sub BindGrid()
        Dim cnt As Integer = CInt(PageBO.Rows.Count)
        Dim idx As Integer = PageSelect1.PageSize * PageSelect1.CurrentPageIndex
        Dim sidx As Integer = PageSelect1.PageSize * PageSelect1.CurrentPageIndex

        Dim dt As DataTable = PageBO.Clone

        While idx < sidx + PageSelect1.PageSize AndAlso idx < cnt
            dt.ImportRow(PageBO.Rows(idx))
            idx += 1
        End While

        Me.dgReports.DataSource = dt
        Me.dgReports.DataBind()

        Me.lblTotal.Text = cnt.ToString

        'create top page select
        Me.PageSelect1.ItemCount = cnt
        Me.PageSelect1.Create()

        'create bottom page select and sync with top page select
        Me.Pageselect2.ItemCount = Me.PageSelect1.ItemCount
        Me.Pageselect2.Create()
    End Sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Me.IsPostBack Then
            Security.InternalAndAdminOnly()

            Header1.MenuIndex = EMenuIndex.InternalReport

            PageBO = COrder.GetCustomerListFromNonRemovedOrders

            Me.PageSelect1.PageSize = Me.PAGE_SIZE
            Me.Pageselect2.PageSize = Me.PageSelect1.PageSize

            Me.BindGrid()

            Me.lblTotalText.Text = "CUSTOMER(S)"
        End If
    End Sub

    Private Sub PageSelect1_PageIndexChanged(ByVal newPageIndex As Integer) Handles PageSelect1.PageIndexChanged
        Me.PageSelect1.CurrentPageIndex = newPageIndex
        Me.Pageselect2.CurrentPageIndex = newPageIndex
        Me.BindGrid()
    End Sub

    Private Sub Pageselect2_PageIndexChanged(ByVal newPageIndex As Integer) Handles Pageselect2.PageIndexChanged
        Me.PageSelect1.CurrentPageIndex = newPageIndex
        Me.Pageselect2.CurrentPageIndex = newPageIndex
        Me.BindGrid()
    End Sub
End Class
